package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.Student;
import com.dkd.manage.service.IStudentService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 学生管理Controller
 * 
 * @author czq
 * @date 2024-11-09
 */
@Api(tags = "学生管理")
@RestController
@RequestMapping("/manage/student")
public class StudentController extends BaseController {

    @Autowired
    private IStudentService studentService;

    /**
     * 查询学生管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:student:list')")
    @ApiOperation(value = "查询学生管理列表", notes = "根据条件查询学生管理列表")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam(value = "学生对象", required = false) Student student) {
        startPage();
        List<Student> list = studentService.selectStudentList(student);
        return getDataTable(list);
    }

    /**
     * 导出学生管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:student:export')")
    @Log(title = "学生管理", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出学生管理列表", notes = "导出符合条件的学生管理列表为Excel文件")
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ApiParam(value = "学生对象", required = false) Student student) {
        List<Student> list = studentService.selectStudentList(student);
        ExcelUtil<Student> util = new ExcelUtil<Student>(Student.class);
        util.exportExcel(response, list, "学生管理数据");
    }

    /**
     * 获取学生管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:student:query')")
    @ApiOperation(value = "获取学生管理详细信息", notes = "根据ID获取学生管理详细信息")
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 404, message = "未找到学生信息")
    })
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "学生ID", required = true) @PathVariable("id") Long id) {
        return success(studentService.selectStudentById(id));
    }

    /**
     * 新增学生管理
     */
    @PreAuthorize("@ss.hasPermi('manage:student:add')")
    @Log(title = "学生管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增学生管理", notes = "新增一条学生管理记录")
    @ApiResponses(value = {
        @ApiResponse(code = 201, message = "创建成功"),
        @ApiResponse(code = 400, message = "请求参数错误")
    })
    @PostMapping
    public AjaxResult add(@ApiParam(value = "学生对象", required = true) @RequestBody Student student) {
        return toAjax(studentService.insertStudent(student));
    }

    /**
     * 修改学生管理
     */
    @PreAuthorize("@ss.hasPermi('manage:student:edit')")
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改学生管理", notes = "根据ID修改学生管理记录")
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "修改成功"),
        @ApiResponse(code = 404, message = "未找到学生信息")
    })
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "学生对象", required = true) @RequestBody Student student) {
        return toAjax(studentService.updateStudent(student));
    }

    /**
     * 删除学生管理
     */
    @PreAuthorize("@ss.hasPermi('manage:student:remove')")
    @Log(title = "学生管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除学生管理", notes = "根据ID删除学生管理记录")
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "删除成功"),
        @ApiResponse(code = 404, message = "未找到学生信息")
    })
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(value = "学生ID数组", required = true) @PathVariable Long[] ids) {
        return toAjax(studentService.deleteStudentByIds(ids));
    }
}